package cn.com.blueInfo.bpm.system.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.system.request.MenuDTO;
import cn.com.blueInfo.bpm.system.response.MenuVO;
import cn.com.blueInfo.bpm.system.service.MenuService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 菜单表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:37:55
 */
@Tag(name = "菜单 接口")
@RestController
@RequestMapping("/bpm/system/menu")
public class MenuController extends BaseController {

    @Autowired
    private MenuService menuService;

    /**
     * 新建菜单
     * @param menuDTO 菜单参数
     * @return ResultInfo
     */
    @Operation(summary = "新增菜单")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createMenu(
            @Validated({Create.class, Default.class}) @RequestBody MenuDTO menuDTO) {
        return menuService.addMenu(menuDTO);
    }

    /**
     * 批量新建菜单
     * @param menuDTOList 菜单参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建菜单")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> createMenu(
            @Validated({Create.class, Default.class}) @RequestBody List<MenuDTO> menuDTOList) {
        return menuService.batchAddMenu(menuDTOList);
    }

    /**
     * 根据ID删除菜单
     * @param menuId 菜单ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除菜单")
    @DeleteMapping("/removeInfo/{menuId}")
    public ResultInfo<Integer> deleteMenuById(
            @Parameter(name = "ID") @PathVariable Long menuId) {
        return menuService.removeMenu(menuId);
    }

    /**
     * 批量根据ID删除菜单
     * @param menuIdList 菜单ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除菜单")
    @DeleteMapping("/removeInfoList/{menuIdList}")
    public ResultInfo<Integer> batchDeleteMenuById(
            @Parameter(name = "ID") @PathVariable List<Long> menuIdList) {
        return menuService.batchRemoveMenu(menuIdList);
    }

    /**
     * 根据ID全量更新菜单
     * @param menuId 菜单ID
     * @param menuDTO 菜单参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新菜单")
    @PutMapping("/modifyInfo/{menuId}")
    public ResultInfo<Integer> updateMenuFull(
            @Parameter(name = "ID") @PathVariable Long menuId,
            @Validated({Update.class, Default.class}) @RequestBody MenuDTO menuDTO) {
        validateUpdateId(menuId, menuDTO.getId());
        return menuService.modifyMenu(menuDTO);
    }

    /**
     * 根据ID部分更新菜单
     * @param menuId 菜单ID
     * @param menuUpdatePartialDTO 菜单参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新菜单")
    @PatchMapping("/modifyPartialInfo/{menuId}")
    public ResultInfo updateMenuPartial(
            @Parameter(name = "ID") @PathVariable Long menuId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            MenuDTO.UpdatePartialDTO menuUpdatePartialDTO) {
        validateUpdateId(menuId, menuUpdatePartialDTO.getId());
        return menuService.modifyMenuPartial(menuUpdatePartialDTO);
    }

    /**
     * 根据ID查询菜单
     * @param menuId 菜单ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询菜单")
    @GetMapping("/getInfo/{menuId}")
    public ResultInfo<MenuVO> getMenuById(
            @Parameter(name = "ID") @PathVariable Long menuId) {
        return menuService.queryMenuById(menuId);
    }

    /**
     * 分页查询菜单
     * @param menuQueryDTO 菜单参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询菜单")
    @GetMapping("/getInfos")
    public ResultInfo<Page<MenuVO>> getMenuPage(
            @Validated MenuDTO.QueryDTO menuQueryDTO) {
        return menuService.queryMenuPage(menuQueryDTO);
    }

    /**
     * 根据条件查询菜单
     * @param menuQueryDTO 菜单参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询菜单")
    @GetMapping("/getInfoList")
    public ResultInfo<List<MenuVO>> getMenuList(
            @Validated MenuDTO.QueryDTO menuQueryDTO) {
        return menuService.queryMenuList(menuQueryDTO);
    }

    /**
     * 获取平台管理菜单
     * @return ResultInfo
     */
    @Operation(summary = "获取平台管理菜单")
    @GetMapping("/getSystemMenu")
    public ResultInfo<List<MenuVO>> getSystemMenu() {
        return menuService.querySystemMenu();
    }

}
